﻿using eProcurement.BLL;
using eProcurement.DAL;
using eProcurement.helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace eProcurement.members
{
    public partial class SupplierProfile : System.Web.UI.Page
    {
        Manager manager = new Manager();

        protected void Page_Load( object sender, EventArgs e )
        {
            if ( !IsPostBack )
            {
                if ( Request[ "sup" ] != null )
                {
                    AppUser user = manager.GetAppUser( Guid.Parse( Request[ "sup" ] ) );
                    if ( user != null )
                    {
                        Hydrate( user );
                    }
                }
            }
        }

        private void Hydrate( AppUser user )
        {
            lblCompanyName.InnerText = user.CompanyName;
            lblAddress1.InnerText = user.Address1;
            lblAddress2.InnerText = user.Address2;
            lblCity.InnerText = user.City;
            lblWebsite.InnerHtml = "<a href='" + SiteFormatter.FormatURL( user.Website ) + "'>" + user.Website + "</a>";
            lblDescription.InnerText = user.Description;

            lblFax.InnerText = "Fax - " + user.Fax;
            lblPhone.InnerText = "Phone - " + user.Telephone;
            lblLiasison.InnerText = "Liaison - " + user.FirstName + " " + user.LastName;
            lnkEmail.Attributes.Add( "href", "mailto:" + user.Username );
            lnkEmail.InnerText = user.Username;
            Project project = manager.GetProject( Convert.ToInt32( Request[ "pid" ] ) );
            if ( project.CloseDate < DateTime.Now )
            {
                lnkDownloadScope.Attributes.Add( "href", "../members/FileHandler.ashx?file=SD&" + "sup=" + user.Id );
            }
            else
            {
                //lnkDownloadScope.Attributes.Add( "href", "../members/Bidders.aspx?pid=" + Request[ "pid" ] );
                btnAwardProject.Enabled = false;
            }
        }

        protected void btnAwardProject_Click( object sender, EventArgs e )
        {
            manager.AwardWinner( Convert.ToInt32( Request[ "bid" ] ) );
        }
    }
}